<?php
//获取图片和文字
//用于预览
//返回示例
/*
{
	"title": [
		"BB",
		"CC",
		"DD",
		"日本小姐姐",
		"杂图"
	],
	"url": [
		"https://kyun.ltyuanfang.cn/tc/2020/07/12/e8f5faef6d65a.jpg",
		"https://kyun.ltyuanfang.cn/tc/2020/07/12/ce50968107b9a.jpg",
		"https://kyun.ltyuanfang.cn/tc/2020/07/12/09ff9ba6c0f9e.jpg",
		"https://kyun.ltyuanfang.cn/tc/2020/07/12/8fccdd9953f80.jpg",
		"https://kyun.ltyuanfang.cn/tc/2020/07/12/0a95837ed15b2.jpg"
	],
	"len": 5
}
*/
require "../config.php";
$conn = new mysqli($MySqlHost, $MySqlUser, $MySqlPwd, $MySqlDatabaseName);
if (!$conn) {
    die("连接失败: " . mysqli_connect_errno());
} else {
    mysqli_query($conn, "set character set 'utf8'"); //读库
    mysqli_query($conn, "set names 'utf8'"); //写库
    $res=mysqli_query($conn,"SELECT album_title FROM img_all GROUP BY album_title");
    $img_and_msg_json = array();  //最终数组
    //获取所有图集标题
    $all_num = mysqli_num_rows($res);
    for($i=0;$i<=$all_num-1;$i++){
        $r = mysqli_fetch_row($res);
        $img_txt[$i]=$r[0];
        $img_and_msg_json['title_data'][$i]=$img_txt[$i];
    }
    //获取所有图集第2张
    for($j=0;$j<count($img_txt);$j++){
        $res = mysqli_query($conn, "SELECT img_url FROM img_all WHERE album_title='$img_txt[$j]'");
        $r = mysqli_fetch_assoc($res);
        $img_and_msg_json['url_data'][$j]=$r['img_url'];
    }
    $img_and_msg_json['len'] = count($img_txt); 
    echo json_encode($img_and_msg_json);
    
}
mysqli_free_result($res);
